#!/usr/bin/env python
# -*- coding: utf-8 -*-

def recall_source(input_file, target):
    source = []
    with open(input_file, 'r+') as f:
        for line in f:
            if '#' in line:
                continue
            arr = line.strip().split('\t')
            if arr[1] == target:
                source.append(arr[0])
    f.close()
    return source

def recall_minus(index_file, source):
    print 'node\t\told\t\tnew\t\tminus: \n'
    with open(index_file, 'r+') as f:
        for line in f:
            arr = line.strip().split('\t')
            if arr[0] in source:
                print line.strip()
                
def main():
    input_file = '/home/ivy/git/BD_py/PageRank_py/project/resource/web-Google.txt'
    index_file = '/home/ivy/git/BD_py/PageRank_py/project/resource/sort_all/index_old_new_minus.txt'
    
    targets = [109274, 443868]
    for target in targets:
        print 'source of %d is below: ' % target
        source = recall_source(input_file, str(target))
        recall_minus(index_file, source)
        print ''
        
    
    
if __name__ == '__main__':
    main()    